<template>
    <section>
        <!--工具条-->
        <div class="searchgrid">
            <div style="float:left;">
                <el-select size="small" style="width:150px" v-model="post_data.where.status" placeholder="用户状态筛选" clearable @change="changeSelect">
                    <el-option
                            v-for="item in status_list"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                  </el-select>
              </div>
            <div style="float: right;">
                <input v-model="post_data.search.id" style="width:120px;height:20px;"
                       value="" maxlength="10" type="text" placeholder="搜索:账户号码">
                <input v-model="post_data.has.client.search.cellphone" style="width:120px;height:20px;"
                       value="" maxlength="10" type="text" placeholder="搜索:手机号">
              <input class="yl-input-button" value=" 查询 " type="button" v-on:click="search">
            </div>

        </div>

        <!--列表-->
        <el-table :data="forms.list"
                  highlight-current-row
                  v-loading="loading"
                  style="width: 100%;">
            <el-table-column prop="id" label="账户号码" show-overflow-tooltip></el-table-column>
            <el-table-column prop="cust_id" label="客户id" show-overflow-tooltip></el-table-column>
            <el-table-column prop="client.nick_name" label="客户姓名" show-overflow-tooltip></el-table-column>
            <el-table-column prop="client.cellphone" label="手机号码" show-overflow-tooltip></el-table-column>
            <el-table-column prop="stock_finance_product.product_name" label="产品名称" show-overflow-tooltip></el-table-column>
            <el-table-column label="用户状态" prop="status" show-overflow-tooltip></el-table-column>
            <el-table-column prop="stock_finance_begin_time" min-width="130" label="配资日期" show-overflow-tooltip></el-table-column>
            <el-table-column prop="stock_finance_settleup" label="结算日期" show-overflow-tooltip></el-table-column>
            <el-table-column prop="stock_finance_product.interests_rate" label="递延费率" show-overflow-tooltip></el-table-column>
            <el-table-column label="起初金额" prop="total_amount" show-overflow-tooltip></el-table-column>
            <el-table-column label="借款金额" prop="current_finance_amount" show-overflow-tooltip></el-table-column>
            <el-table-column label="可用额度" prop="available_amount" show-overflow-tooltip></el-table-column>
            <el-table-column label="总资产" prop="stock_finance.totalAssert" show-overflow-tooltip></el-table-column>
            <el-table-column label="证券市值" prop="stock_finance.stockFinanceMarketValue" show-overflow-tooltip></el-table-column>
            <el-table-column label="盈亏金额" prop="stock_finance.winLoss" show-overflow-tooltip></el-table-column>
            <el-table-column label="操作">
                <template scope="scope">
                    <router-link :to="{path:'/stock/uStockFinancings/'+scope.row.id}">
                        交易查询
                    </router-link>
                    <a v-if="isUserSystemAdmin" href="javascript:void(0);" @click="edit(scope.row)" :class="{link_not_allow:(scope.row.status=='已结算')}">修改</a>
                </template>
            </el-table-column>
        </el-table>

        <!--工具条-->
        <div class="pagination">
        <el-col :span="24" class="toolbar">
            <el-pagination
                    @size-change="changeSize"
                    @current-change="pageChange"
                    :current-page="post_data.offset/post_data.limit+1"
                    :page-sizes="[15, 30, 45, 60]"
                    :page-size="post_data.limit"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="forms.count"
                    style="float:left;">
            </el-pagination>
        </el-col>
        </div>
    </section>
</template>


<script type="text/ecmascript-6">
    import {getUStockFinancings} from '../../../api/stock';
    export default {
        data() {
            return {
                status_list: [{value: 1, label: '操盘中'}, {value: 2, label: '单向冻结'}, {value: 3, label: '双向冻结'}, {value: 4, label: '已结算'}],
                loading: false,
                forms:{},
                post_data:{
                    field: ['*', '"" as stock_finance', '"" as total_amount'],
                    search:{
                        id: ''
                    },
                    where: {
                        status:''
                    },
                    count:true,
                    offset:0,
                    limit: 15,
                    stock_finance_product:{
                        field: ['id', 'product_name', 'interests_rate']
                    },
                    client:{
                        field:['id','nick_name','cellphone']
                    },
                    has:{
                        client:{
                            search:{
                                cellphone:''
                            }
                        }
                    },
                    order: 'id desc'
                }
            }
        },
        created(){
            this.getList();
        },
        methods: {
            edit: function (row) {
                if (row.status == '已结算') return;
                this.$router.push({path: '/stock/uStockFinancing/edit/' + row.id});
            },
            getList: function(){
                this.loading = true;
                getUStockFinancings(this.post_data).then(res => {
                    this.loading = false;
                    if (res.status === 0) return this.ezNotifyAxiosThen(res);
                    this.forms = res.data;
                }).catch(error => this.ezNotifyAxiosCatch(error));
            },
            pageChange: function (index) {
                this.post_data.offset = (index-1)*this.post_data.limit;
                this.getList();
            },
            changeSize: function (num) {
                this.post_data.offset = 0;
                this.post_data.limit = num;
                this.getList();
            },
            search: function () {
                this.post_data.offset = 0;
                this.getList();
            },
            changeSelect: function(value){
                this.post_data.offset = 0;
                this.getList();
            }
        }
    }
</script>

<style scoped>
    .link_not_allow {
        cursor: not-allowed;
        color: #aaa;
    }
</style>
